package com.litchi.tutor.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.litchi.tutor.common.cons.RedisKey;
import com.litchi.tutor.common.entity.College;
import com.litchi.tutor.common.util.RedisUtil;
import com.litchi.tutor.mapper.CollegeMapper;
import com.litchi.tutor.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author XuRuiPeng
 * @date 2021/11/1 16:54
 */
@Service
public class CollegeServiceImpl extends ServiceImpl<CollegeMapper, College> implements CollegeService {

    @Autowired
    RedisUtil redisUtil;

    @Override
    public List<College> getCollege() {
        String college = redisUtil.get(RedisKey.COLLEGE_LIST);
        List<College> colleges = JSONObject.parseArray(college, College.class);
        if (colleges != null) {
            return colleges;
        } else {
            List<College> list = list();
            redisUtil.set(RedisKey.COLLEGE_LIST, list);
            return list;
        }
    }
}
